package com.luguokong.pet_rescue.controller;

import com.luguokong.pet_rescue.pojo.Order;
import com.luguokong.pet_rescue.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderCtrl {
    @Autowired
    private OrderService orderService;

    @GetMapping("/getByPage")
    public List<Order> selectOrderAllByPageNumByPageSize(int pageNum, int pageSize){
        List<Order> orderList = orderService.selectOrderAllByPageNumByPageSize((pageNum-1)*pageSize, pageSize);
        return orderList;
    }

    @GetMapping("/getDataCount")
    public int selectDataCount(){
        int i = orderService.selectDataCount();
        return i;
    }

    @PostMapping("/insertOrder")
    public int insertOrder(@RequestBody Order order){
        int i = orderService.insertOrder(order);
        return i;
    }

    @GetMapping("/deleteOrderById")
    public int deleteOrderById(int orderId){
        int i = orderService.deleteOrderById(orderId);
        return i;
    }

    @PostMapping("/updateOrderById")
    public int updateByOrderId(@RequestBody Order order){
        int i = orderService.updateOrderById(order);
        return i;
    }

    //    查询每个宠物类型的订单数量
    @GetMapping("/selectGroupByPetType")
    public List<Map<String, Number>> selectGroupByPetType(){
        List<Map<String, Number>> mapList = orderService.selectGroupByPetType();
        return mapList;
    }

}
